package com.zeei.ems.meet.controller;

import com.github.pagehelper.PageInfo;
import com.zeei.ems.base.constant.GlobalConstant;
import com.zeei.ems.base.controller.BasicController;
import com.zeei.ems.base.page.PageParamVO;
import com.zeei.ems.base.result.ResultBasicVO;
import com.zeei.ems.base.result.ResultRowsVO;
import com.zeei.ems.base.util.StringUtil;
import com.zeei.ems.meet.model.MeetingContactVO;
import com.zeei.ems.meet.model.vo.MeetingContactParam;
import com.zeei.ems.meet.service.MeetingContactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "通讯录接口")
@RestController
@RequestMapping("/ems/meeting/contact")
public class MeetingContactController extends BasicController {
    @Autowired
    MeetingContactService meetingContactService;

    /**
     * 查询通讯录信息
     * @param meetingContact 通讯录信息
     * @return 返回通讯录信息列表
     */
    @ApiOperation(value = "分页查询通讯录信息列表")
    @PostMapping("/page/list")
    public ResultRowsVO<MeetingContactVO> listMeetingContactPage(PageParamVO page,
                                                             @RequestBody MeetingContactParam meetingContact){
        PageInfo<MeetingContactVO> meetingContactVOPageInfo = meetingContactService.listMeetingContact(page, meetingContact);
        return this.createResultRowsVO(meetingContactVOPageInfo, GlobalConstant.SUCCEED, "");
    }

    /**
     * 查询通讯录信息
     * @param meetingContact 通讯录信息
     * @return 返回通讯录信息列表
     */
    @ApiOperation(value = "查询通讯录信息列表")
    @PostMapping("/list")
    public ResultRowsVO<MeetingContactVO> listMeetingContact(@RequestBody MeetingContactParam meetingContact){
        List<MeetingContactVO> meetingContactList = meetingContactService.listMeetingContact(meetingContact);
        return this.createResultRowsVO(meetingContactList, GlobalConstant.SUCCEED, meetingContactList.size());
    }

    /**
     * 新增通讯录
     * @param meetingContact 通讯录信息
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "新增通讯录信息")
    @PostMapping("/add")
    public ResultBasicVO addMeetingContact(@RequestBody MeetingContactVO meetingContact){
        Boolean result = meetingContactService.addMeetingContact(meetingContact);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 新增通讯录
     * @param meetingContact 通讯录信息
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "更新通讯录信息")
    @PostMapping("/update")
    public ResultBasicVO  updateMeetingContact(@RequestBody MeetingContactVO meetingContact){
        Boolean result = meetingContactService.updateMeetingContact(meetingContact);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 新增通讯录
     * @param userIdList 用户ID集合
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "删除通讯录信息")
    @PostMapping("/delete")
    public ResultBasicVO  deleteMeetingContact(@RequestBody List<Integer> userIdList){
        Boolean result = meetingContactService.deleteMeetingContact(userIdList);
        return this.createResultBasicVO(result, StringUtil.empty());
    }
}
